﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace ImaginationFactory.Dialogs
{
    /// <summary>
    /// ImageSizeDialog.xaml 的交互逻辑
    /// </summary>
    public partial class ImageSizeDialog : Window
    {
       static double imageScaleHeight;
       static double imageScaleWidth;
       static MainWindow mWindowTemp;
       //static MainListBox mListBox;

        public ImageSizeDialog ( MainWindow mWindow )
        {
            InitializeComponent();
            mWindowTemp = mWindow;

            txtImageScaleHeight.Text = mWindowTemp.ImageLibrary.Height.ToString();
            txtImageScaleWidth.Text = mWindowTemp.ImageLibrary.Width.ToString();
        }



        private void Button_Click( object sender, RoutedEventArgs e )
        {
            mWindowTemp.ImageLibrary.ScaleImage( imageScaleWidth / mWindowTemp.ImageLibrary.Width, 
                imageScaleHeight / mWindowTemp.ImageLibrary.Height );

            mWindowTemp.image.Source = mWindowTemp.ImageLibrary.LoadedImage.Source;
            //mListBox.imageSizeItem.IsSelected = false;
            this.Close();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //mListBox.imageSizeItem.IsSelected = false;
            this.Close();
        }

        private void ImageSizeDlg_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }
        
        private void txtImageScaleHeight_TextChanged(object sender, TextChangedEventArgs e)
        {

            if ( Convert.ToDouble( txtImageScaleHeight.Text ) > 1 
                && Convert.ToDouble( txtImageScaleHeight.Text ) < mWindowTemp.ImageLibrary.Height * 10 )
            {
                imageScaleHeight = Convert.ToDouble(txtImageScaleHeight.Text);
                //是double型且在合理范围内
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请输入1--原图像10倍的数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //不是double型
            } 
        }

        private void txtImageScaleWidth_TextChanged(object sender, TextChangedEventArgs e)
        {
            if( Convert.ToDouble(txtImageScaleWidth.Text) > 1 
                && Convert.ToDouble( txtImageScaleWidth.Text ) < mWindowTemp.ImageLibrary.Width * 10 )
            {
                imageScaleWidth = Convert.ToDouble(txtImageScaleWidth.Text);
                //是double型且在合理范围内
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请输入0.1--10的数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //不是double型
            } 

        }



    }
}
